<?php
// 设置接诊状态
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");
include_once("d_getLoginInfo.php");
$sql = "SELECT * FROM doc_infos WHERE doc_ID = '" . $doc_ID . "'";
if (isset($_GET['action'])) {
    $action = $_GET['action'];
} else {
    $action = "";
}
if ($action == "") {
    if ($result = mysqli_query($connect_DB, $sql)) {
        $row = mysqli_fetch_object($result);
        echo "<h3>当前接诊状态</h3>";
        if ($row->doc_Accept == 1) {
            $nowStatus = "已开启";
            $status = 0;
            $btn = "<button type='button' class='btn btn-outline-danger' onclick='changeSet()'>切换为停止预约</button>";
        } else {
            $status = 1;
            $nowStatus = "已停止";
            $btn = "<button type='button' class='btn btn-outline-success' onclick='changeSet()'>切换为开始预约</button>";
        }
        echo "<p>" . $nowStatus . "</p>" . $btn;
    } else {
        echo "
    <h3>数据库异常</h3>
    <p>状态未知</p>
    <button type='button' class='btn btn-outline-success' onclick='changeSet()'>点我重试</button>
    ";
    }
}


if ($action == "change") {
    if($result = mysqli_query($connect_DB, $sql)){
        $row = mysqli_fetch_object($result);
    }
    if ($row->doc_Accept == 1) {
        $status = 0;
    }else{
        $status = 1;
    }
    $update = "UPDATE doc_infos SET doc_Accept = " . $status . " WHERE doc_ID = '" . $doc_ID . "'";
    if (mysqli_query($connect_DB, $update)) {
        $sql = "SELECT * FROM doc_infos WHERE doc_ID = '" . $doc_ID . "'";
        if ($result = mysqli_query($connect_DB, $sql)) {
            $row = mysqli_fetch_object($result);
            echo "<h3>当前接诊状态</h3>";
            if ($row->doc_Accept == 1) {
                $nowStatus = "已开启";
                $btn = "<button type='button' class='btn btn-outline-danger' onclick='changeSet()'>切换为停止预约</button>";
            } else {
                $nowStatus = "已停止";
                $btn = "<button type='button' class='btn btn-outline-success' onclick='changeSet()'>切换为开始预约</button>";
            }
            echo "<p>" . $nowStatus . "</p>" . $btn;
        } else {
            echo "
            <h3>数据库异常</h3>
            <p>状态未知</p>
            <button type='button' class='btn btn-outline-success' onclick='changeSet()'>点我重试</button>
            ";
        }
    }
}


$connect_DB->close();
?>